app.controller("dayController",function($scope, $http,$filter){
    // 超级管理员权限
    $http({
        method: 'GET',
        url: '/OA/staff/roles',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).success(function (response) {
        $scope.roles=[];
        $scope.roles=response.data;
        console.log($scope.roles)
        function permissions(){
            var rs=false;
            for (var i = 0; i < $scope.roles.length; i++) {
                if ($scope.roles[i] == 7) {
                    rs = true;
                }else{
                    rs= false;
                }

            }
            return rs
        }
        $scope.admin=permissions();
        console.log($scope.admin)
    })
   // 一对一
    function  finddata() {
        var campus_id=$("#schoolcampus").find("option:selected").val();
        $http({
            method: 'POST',
            url: '/OA/classone2one/list ',
            data:$.param({class_date:$scope.date,campus_id:campus_id}),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (response) {
            if(response.ok==true){
                console.log(response)
                $scope.datas=response.data;
           $scope.Sign=function ($index) {
             $scope.sign_id=$scope.datas[$index].id;
              $http({
                  method: 'POST',
                  url: '/OA/classone2one/signin',
                  data:$.param({id:$scope.sign_id}),
                  headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
              }).success(function (result) {
                  console.log(result)
                  if(result.ok==true){
                      $scope.state=$scope.datas[$index].state;
                      $(".signin").eq($index).css({background:"red"})
                  }
              })
             }
   // 取消签到
                $scope.Signout=function ($index) {
                    $scope.sign_id=$scope.datas[$index].id;
                    $http({
                        method: 'POST',
                        url: '/OA/classone2one/signout',
                        data:$.param({id:$scope.sign_id}),
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                    }).success(function (result) {
                        console.log(result)
                        if(result.ok==true){
                            $scope.state=$scope.datas[$index].state;
                            $(".signin").eq($index).css({background:"#a5d16d"})
                        }
                    })
                }


           }
        })
    }
    finddata()
    // 班课
    arranging()
    function arranging() {
        var campus_id=$("#schoolcampus").find("option:selected").val();
        $http({
            method: 'POST',
            url: '/OA/classclazz/list',
            data:$.param({class_date:$scope.date,campus_id:campus_id}),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (response) {
            $scope.classdatas=response.data;
            console.log($scope.classdatas)
        })
    }
    // 日历时间调用
    $(function () {
        $('#calendar').calendar({
            ifSwitch: true, // 是否切换月份
            hoverDate: true, // hover是否显示当天信息
            backToday: true // 是否返回当天
        });
        var  item=$(".calendar-date>.item");
        item.click(function(){
            index=$(this).index();
            item.attr("class","item item-curMonth");
            $(this).attr("class","item item-curDay");
            dataTime=item.eq(index).attr('data');
            dataTime=dataTime.split('');
            dataTime.splice(4,0,'/');
            dataTime.splice(7,0,'/');
            dataTime=dataTime.join('');
            clickTime=new Date(dataTime);
            unixTime=clickTime.getTime();
            $scope.date = $filter("date")(unixTime, "yyyy-MM-dd");
            console.log($scope.date)
            finddata()
            arranging()
        })
    });

})